package com.example.controller;

import com.example.entity.Jiaoyi;
import com.example.entity.JiaoyiType;
import com.example.service.IJiaoyiService;
import com.example.service.IJiaoyiTypeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/dingdan")
public class JiaoyiController {
    @Autowired
    private IJiaoyiService jiaoyiService;

    @Autowired
    private IJiaoyiTypeService jiaoyiTypeService;

    @GetMapping("/index")
    public String index(String name, Integer typeId, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "7") Integer pageSize, HttpServletRequest request){

        PageInfo<Jiaoyi> pageInfo = jiaoyiService.findAll(name,typeId,pageNum,pageSize);
        System.out.println(pageInfo+"=====>");
        request.setAttribute("pageInfo",pageInfo);

        //产品类型
        List<JiaoyiType> typeList = jiaoyiTypeService.findAll();

        request.setAttribute("typeList",typeList);

        //数据的回显
        request.setAttribute("typeId",typeId);

        request.setAttribute("name",name);

        return "dingdan/ddan";
    }
}
